package com.loyal.loyalerp.basedata.company.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;

import com.loyal.loyalerp.basedata.company.mapper.provider.GyCompanyProvider;
import com.loyal.loyalerp.basedata.company.model.GyCompany;

@Mapper
public interface GyCompanyMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(GyCompany record);

    int insertSelective(GyCompany record);

    GyCompany selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(GyCompany record);
    
    int selectCompanyIDByName(String name);
    
    int updateByPrimaryKey(GyCompany record);
    
    @Select("select * from gy_company")
	List<GyCompany> companyList();
    @Select("select * from gy_company order by Id desc")
    List<GyCompany> companyListDesc();
    @Select("select * from gy_company where ParentId=#{id}")
    List<GyCompany> findChildrens(Integer id);
    /**
     * 查看该公司的子公司个数
     * @param parentid
     * @return
     */
    @Select("SELECT COUNT(*) FROM gy_company WHERE ParentId=#{id}")
	int countChildren(Integer id);
    @Update("UPDATE gy_company SET ParentId=0 WHERE ParentId=#{id}")
	int updateResetParentId(Integer id);
    @Update("UPDATE gy_company SET EndFlag=0 WHERE Id=#{id}")
	int updateEndflagById(Integer id);   
    @Update("UPDATE gy_company SET EndFlag=1 WHERE Id=#{id}")
   	int resetEndFlag(Integer id);
    @Update("UPDATE gy_company SET CodeLevel=CodeLevel+#{level} WHERE Id=#{id}")
	void subLevel(@Param(value="id")Integer id,@Param(value="level")int level);
    @SelectProvider(type=GyCompanyProvider.class,method="searchList")
    List<GyCompany> companySearchList(String searchField,String searchString,String sord);
    @SelectProvider(type=GyCompanyProvider.class,method="searchListByCompanyName")
	List<GyCompany> companySearchListByParentName(String searchField, String searchString,String sord);
   
   
}